﻿using System;
using System.Linq;
using Anmlz.Model.Entities;
using Anmlz.Model.Model;
using Anmlz.Services;

namespace Anmlz.Data.ModelFactory
{
    public partial class ModelFactory
    {
        public CreatureTemperament Parse(CreatureTemperamentModel model, bool creation = false)
        {
            try
            {
                CreatureTemperament entity = null;

                if (!creation)
                {
                    entity = model.Id == 0 ? 
                        this._unitOfWork.GetCreatureTemperamentByName(model.Name) : 
                        this._unitOfWork.CreatureTemperaments.GetById(model.Id);
                }
                if (entity == null)
                {
                    entity = new CreatureTemperament();
                }

                switch (_languageService.GetCurrentLanguage())
                {
                    case CultureNames.English:
                        entity.NameEn = model.Name;
                        break;
                    case CultureNames.Russian:
                        entity.NameRu = model.Name;
                        break;
                }

                return entity;

            }
            catch (Exception)
            {
                return null;
            }
        }

        public CreatureTemperamentModel Create(CreatureTemperament entity)
        {
            var model = new CreatureTemperamentModel()
                            {
                                Id = entity.Id
                            };
            switch (_languageService.GetCurrentLanguage())
            {
                case CultureNames.English:
                    model.Name = entity.NameEn;
                    break;
                case CultureNames.Russian:
                    model.Name = entity.NameRu;
                    break;
            }
            return null;
        }
    }
}